package com.Liuhang.Dao;

import com.Liuhang.JDBC.util;
import com.Liuhang.entity.user;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;

import javax.servlet.http.HttpServlet;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

public class getUserList {
    public static List list ;
    public static ResultSet rs;

    public static List getList(){
        list = new ArrayList();
        String sql = "select * from t_emp t,t_dep d WHERE t.dep_id=d.pid ORDER BY id ASC limit 0,10; ";
        try {
            Statement st = util.getStatement();
            rs = st.executeQuery(sql);
            while (rs.next()){
                System.out.println("id = "+rs.getObject("id"));
                System.out.println("name = "+rs.getString("name"));
                System.out.println("sex = "+rs.getString("sex"));
                System.out.println("deparment ="+rs.getString("dep_name"));
                user u = new user();
                u.setId((Integer) rs.getObject("id"));
                u.setName(rs.getString("name"));
                u.setSex(rs.getString("sex"));
                u.setDep_name(rs.getString("dep_name"));
                u.setMoney(rs.getInt("money"));
                u.setPhone(rs.getInt("phone"));
                u.setPasswd(rs.getString("passwd"));
                //u1.setPhone((Integer) rs.getObject("phone"));

                list.add(u);

            }
            for (int i = 0; i <list.size() ; i++) {
                user u1 = (user) list.get(i);
                System.out.println(u1);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

        return list;
    }

}
